''''''

# Standard
# Related
import lx
# Local
import mosh.generic_utilities


_layerservice = lx.Service('layerservice')
_layerservice_query = _layerservice.query
_layerservice_select = _layerservice.select

def get_all_vertex_indices():
    ''''''
    _layerservice_select('layer.id', 'selected')

    _layerservice_select('verts', 'all')
    return mosh.generic_utilities.convert_strings_to_ints(
        _layerservice_query('verts'))

def get_selected_vertex_indices():
    '''Get the indices of the selected vertices.

    @important: This automatically goes by the user selected mesh item.
    This may not be preferable so options should be supplied in the future.

    @todo: Add more depth to this command, to handle the possibility of
    multiple mesh items being selected. One idea is to return tupple groups
    if verts from multiple mesh items are currently selected.
    eg: ((item_id, (vert_indices)), (item_id, (vert_indices)))
    '''
    _layerservice_select('layer.id', 'selected')

    _layerservice_select('verts', 'selected')
    return mosh.generic_utilities.convert_strings_to_ints(
        _layerservice_query('verts'))

def get_symmetrical_vertex(mesh_id, vertex_index):
    '''Get what modo considers the symmetrical vertex. Note that for this to
    work at all, some form of symmetry has to be enabled, or this
    will always return None.'''

    _layerservice_select('layer.name', mesh_id)

    _layerservice_select('vert.symmetric', str(vertex_index))

    result = _layerservice_query('vert.symmetric')

    if result:
        return int(result)
    else:
        return None

def get_vertex_position(mesh_id, vertex_index):
    ''''''

    _layerservice_select('layer.name', mesh_id)

    _layerservice_select('vert.pos', str(vertex_index))

    return _layerservice_query('vert.pos')

def is_vertex_selected(mesh_id, vertex_index):
    '''Return True if the vertex is selected by the user. False otherwise.
    '''

    _layerservice_select('layer.name', mesh_id)

    _layerservice_select('vert.selected', str(vertex_index))

    return not not _layerservice_query('vert.selected')
